//
//  main.swift
//  Archive
//
//  Created by LiynXu on 2016/9/30.
//  Copyright © 2016年 LiynXu. All rights reserved.
//

import Foundation

print("Hello, World!")




func sysArchive() {
    let  array = ["one","two","three","four"]
    let dict = ["one":1,"two":2]
    
    print(NSHomeDirectory())
    
    //创建文件路径
    
    let filePath = NSHomeDirectory()+"/Desktop/dictionary"
    
    //let data = NSKeyedArchiver.archivedDataWithRootObject(dict)
    
    let ret = NSKeyedArchiver.archiveRootObject(dict, toFile: filePath)
    //NSFileManager.defaultManager().createFileAtPath(filePath, contents: data, attributes: nil)
    if ret {
        print("Done")
    }else{
        print("ERROR")
    }
    
    let infodict  = try! NSFileManager.defaultManager().attributesOfItemAtPath(filePath)
    /*do {
        try
            NSFileManager.defaultManager().attributesOfItemAtPath(filePath)
    }
    catch{
        
    }*/
    
    print(infodict)
    
    
    
    let diction:Dictionary = NSKeyedUnarchiver.unarchiveObjectWithFile(filePath) as! Dictionary<String,Int>
    print(diction)
}

func customArchive()  {
    
    let midel = Model(number: 34, identifer: "0509")
    let ret = NSKeyedArchiver.archiveRootObject(midel, toFile: NSHomeDirectory()+"/Desktop/customData")
    
    let data = NSKeyedUnarchiver.unarchiveObjectWithFile(NSHomeDirectory()+"/Desktop/customData") as! Model
    print(data.number)
    print(data.identifer)
    
}

customArchive()
//sysArchive()



//Linux
//Unix




